package com.itheima.reggie.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLNonTransientException;

/**
 * 全局异常处理类
 */
@RestControllerAdvice
public class GlobalException {
    /**
     * 用户名重复异常
     *
     * @param se
     * @return
     */
    @ExceptionHandler(SQLNonTransientException.class)
    public R headLer(SQLNonTransientException se) {
        se.printStackTrace();
        return R.error(se.getMessage().split(" ")[2] + "重复");
    }

    /**
     * 自定义异常处理
     *
     * @param ce
     * @return
     */
    @ExceptionHandler(CustomerException.class)
    public R headLer(CustomerException ce) {
        return R.error(ce.getMessage());
    }
}
